package com.example.aircraft;

import android.view.DragEvent;
import android.view.MotionEvent;
import android.view.View;

import com.example.aircraft.aircraft.HeroAircraft;
import com.example.aircraft.gamemode.GameBase;

/**
 * 控制英雄机移动
 */
public class HeroController {
    private GameBase game;
    private HeroAircraft hero;
//    private Adapter touchAdapter;

    public HeroController(GameBase game, HeroAircraft hero){
        this.game = game;
        this.hero = hero;
        DragEvent dragEvent;
        this.game.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                float X,Y;
                if(motionEvent.getX()<200&&motionEvent.getY()<200){
                    return true;
                }
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        X = motionEvent.getX();
                        Y = motionEvent.getY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        X = motionEvent.getX();
                        Y = motionEvent.getY();
                        hero.setLocation(X,Y);
                        break;
                    case MotionEvent.ACTION_UP:
                        break;
                    case MotionEvent.ACTION_CANCEL:
                        break;
                }

                return true;
            }
        });
//                float x = dragEvent.getX();
//                float y = dragEvent.getY();
//                if ( x<0 || x> MyApplication.getContext().getResources().getDisplayMetrics().widthPixels
//                        || y<0 || y> MyApplication.getContext().getResources().getDisplayMetrics().heightPixels){
//                    // 防止超出边界
//                    return true;
//                }
//                hero.setLocation((int)x, (int)y);
//
//                return false;
//            }
//        );

    }
}
